import Vue from 'vue'
import Vuex from 'vuex'
import { getItem, setItem } from '../utils/storage'
const TOKEN = 'TOUTIAO_USER'
Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    // 获取数据
    user: getItem(TOKEN)
    // user: JSON.parse(window.localStorage.getItem('TOUTIAO_USER'))
  },
  mutations: {
    setUser (state, data) {
      state.user = data
      // 数据备份
      // window.localStorage.setItem('TOUTIAO_USER', JSON.stringify(user))
      setItem(TOKEN, state.user)
    }
  },
  actions: {},
  modules: {}
})
